//logs.js
const util = require('../../utils/util.js')

Page({
  data: {
    typeList: [{
        name: "热销1",
        id: 'rexiao1'
      },
      {
        name: "热销2",
        id: 'rexiao2'
      },
      {
        name: "热销3",
        id: 'rexiao3'
      },
      {
        name: "热销4"
      },
      {
        name: "热销5"
      },
      {
        name: "热销6"
      },
    ],
    detailsList: [{
      "id": "rexiao1",
      "data": [{
        name: '麻婆豆腐0',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐0',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐0',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐0',
        total: '8888',
        pirce: '88',
        number: 0
      }]
    }, {
      "id": "rexiao2",
      "data": [{
        name: '麻婆豆腐1',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐1',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐1',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐1',
        total: '8888',
        pirce: '88',
        number: 0
      }]
    }, {
      "id": "rexiao3",
      "data": [{
        name: '麻婆豆腐2',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐2',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐2',
        total: '8888',
        pirce: '88',
        number: 0
      }, {
        name: '麻婆豆腐2',
        total: '8888',
        pirce: '88',
        number: 0
      }]
    }],
    detailsListId: 'id',
    typeIndex: '0',
    total: 0,
    totalNum: 0
  },
  changetype: function(e) {
    this.setData({
      typeIndex: e.target.dataset.index,
      detailsListId: e.target.dataset.id
    })

  },
  cutNum: function(e) {
    const index = e.currentTarget.dataset.index;
    const bigIndex = e.currentTarget.dataset.bigindex;
    let list = this.data.detailsList;
    let num = list[bigIndex].data[index].number;
    if (num > 0) {
      num = num - 1;
    } else {
      return false
    }
    list[bigIndex].data[index].number = num;
    this.setData({
      detailsList: list
    });
    this.count(bigIndex, index, 1)
  },
  addNum: function(e) {
    const index = e.currentTarget.dataset.index;
    const bigIndex = e.currentTarget.dataset.bigindex;
    let list = this.data.detailsList;
    let num = list[bigIndex].data[index].number;
    num = num + 1;
    list[bigIndex].data[index].number = num;
    this.setData({
      detailsList: list
    });
    this.count(bigIndex,index,0)
  },
  count: function (bigIndex, index,type) {
    let count = 0;
    let number = 0;
    let list = this.data.detailsList;
    if(type==0){
      count = this.data.total+ list[bigIndex].data[index].pirce*1
      number = this.data.totalNum+1
    }else{
      count = this.data.total-list[bigIndex].data[index].pirce*1
      number = this.data.totalNum -1
    }
    this.setData({
      total: count,
      totalNum:number
    })
    
  },
  scroll:function(e){
    // console.log(e.detail.scrollTop)
  },
  goPay: function() {
    wx.navigateTo({
      url: '../details/details',
    })
  },
  onLoad: function() {

  }
})